package com.lanou.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

// tomcat8之前默认字符编码iso,之后是utf-8
@WebFilter("/*")
public class AFilter implements Filter {
    // 初始化方法
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    // 执行过滤方法
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        // post请求体字符编码指定为utf-8
        servletRequest.setCharacterEncoding("utf-8");
        // 放行
        filterChain.doFilter(servletRequest, servletResponse);
    }

    // 销毁方法
    @Override
    public void destroy() {

    }
}